package com.tanhua.server.controller;

import com.tanhua.server.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    /**
     * 客户端，上报地理位置信息
     *  请求：POST /location
     */
    @PostMapping("/location")
    public ResponseEntity location(@RequestBody Map<String,Object> map) {
        //1、获取经纬度
        Double latiude = (Double) map.get("latitude"); //经度
        Double longitude = (Double) map.get("longitude"); //纬度
        //2、获取地理位置
        Object addrStr = map.get("addrStr");
        String address = "";
        if(addrStr != null) {
            address = (String) addrStr;
        }
        //3、调用service
        return baiduService.saveLocation(latiude,longitude,address);
    }
}
